<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    var fun = function (arr) {
        var obj = {}
        for (let i = 0; i < arr.length; i++) {
            var v = arr[i];
            //将数组的i个元素作为obj对象的属性查看其属性值
            var counts = obj[v];
            //如果obj对象没有该属性，则设置该属性的值为1，有的话在其基础上再+1
            if (counts) {
                obj[v] += 1;
            } else {
                obj[v] = 1;
            }

        }
        console.log(obj)
    }([1, 2, 3, 4, 4, 4, 4, 2, 3, 3, 2, 3, 2, 1, 6])
</script>

</html>